package com.cvv.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cvv.dao.*;
import com.cvv.entity.*;

import javax.servlet.http.HttpServletRequest;


/**
 * Created by Xander on 2018-06-14.
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @RequestMapping(value = "/login",method = RequestMethod.GET)
    @ResponseBody
    public String loginUser(String user, String password, String verifyCode, HttpServletRequest request){
        User users=userMapper.selectUser(user,password);
        System.out.println(users);
        String code= (String) request.getSession().getAttribute("checkCodes");
        if(users!=null){
            if(code.equals(verifyCode)){
            	request.getSession().setAttribute("user",users);
                request.getSession().setAttribute("user",users);
                return "登录成功！";
            }
            return "验证码错误！(区分大小写)";
        }
        return "账号或密码错误";
    }
    //
//    @RequestMapping(value = "selectAlluser", method = RequestMethod.GET)
//    @ResponseBody
//    public List<Userinfo> selectAll() {
//        System.out.println(userinfoMapper);
//        List<Userinfo> list = null;
//        list = userinfoMapper.selectAll();
//        return list;
//    }
//    @RequestMapping(value = "headUpload", method = RequestMethod.POST)
//    public String fileUpload(HttpServletRequest request, String mark) {
//        System.out.println("执行fileUpload方法");
//        MultipartHttpServletRequest req = (MultipartHttpServletRequest) request;
//        MultipartFile file = req.getFile("pic");
//        String path = request.getRealPath("/imges") + "/" + file.getOriginalFilename();
//        File destFile = new File(path);
//        System.out.println(path);
//        try {
//            FileUtils.copyInputStreamToFile(file.getInputStream(), destFile);
//            System.out.println("上传成功");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return "test";
//    }
//
//    @RequestMapping("/success")
//    public String success() {
//        return "success";
//    }

}
